import {
  axios_base_get,
  axios_base_post,
} from "../../../../utils/axios";

import { dataRegexp } from "../../../../utils/tools";
import { axFormValidator } from "../../../../components/ax-validator";
// import {
//   axios_base_get,
// } from 'utils/axios.js';
const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    fileList: [],
    checked: true,
    fields: {
      question: {
        label: "问题类型",
        required: true,
      },
      describe: {
        label: "具体描述",
        required: true,
      },
      phone: {
        label: "手机号",
        value: app.globalData.phone,
        required: true,
      },
    },
    questionArr: [],
    detail: [],
    show: false,
    image: [],
    message:'',
    id:null
  },

  //回复
  reply() {
    this.setData({ show: true });
  },
  onOk(event) {
    const {message,id}=this.data
    console.log(message);
    axios_base_post(
      "/Question/Reply",
      {
        id: id,
        content:message
      },
      true
    ).then((res) => {
      if (res.success) {
        wx.showToast({
          title: '添加成功',
          icon:'success'
        })
        this.getDetail(id)
       this.setData({
         show:false
       })
      }
    });
  },
  onChange(event) {
    // event.detail 为当前输入的值
    console.log(event.detail);
    this.setData({
      message:event.detail
    })
  },
  onClose() {
    this.setData({ show: false });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options.questionStatus)
    this.getDetail(options.id);
    this.setData({
      id:options.id,
      questionStatus:options.questionStatus
    })
  },
  //获取问题详情
  getDetail(id) {
    axios_base_get(
      "/Question/HandlingDetails",
      {
        id: id,
      },
      true
    ).then((res) => {
      if (res.success) {
        let data = res.data;
        let imageurl=JSON.parse(data.urls)
        imageurl.map(item=>{
          item.url=item.src
        })
        this.setData({
          "fields.question.value": data.typeName,
          "fields.describe.value": data.content,
          detail: data.dtoReplyss,
          image: imageurl,
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
